Skip to main content

Chapter 37 - Terraform Cloud - Sentinel Policies

Investigate and learn about policies https://developer.hashicorp.com/terraform/cloud-docs/policy-enforcement/sentinel

Overview

Types:

  • Advisory mode - Just tells you what is wrong
  • Soft-Mandatory - ability to override
  • Hard-Mandatory - unable to deploy resources

Different Policies

  • allowed providers
  • mandatory tags
  • limit cost
  • restrict vm publisher
  • restrict vm size

Hashicorp Guidelines


Example policies you can use with your Terraform. https://github.com/hashicorp/terraform-guides

Example Policies:


image.png

image.png

Demo


  1. Go to your TF Cloud Organization
  2. Check your plan and billing so that you can use Sentinel Policies
  3. Create a demo workspace
  4. Set up your environment variables for Azure
  5. Create your Git repo
  6. Copy your test code from folder 58 and commit and push
  7. Create your policy sets in Terraform Cloud.
  8. Select your (or create) your VCS (Git) connection.
  9. Select your repo
  10. Click on Policy Source and select the path to the policies.
  11. Connect the policy set - set on selected workspaces, not all, unless you know what you're doing in that regard.
  12. Execute the plan and apply commands
  13. Play with the policies and try to get them to fail.